package edu.zut.main.thread;

public class ThreadYield {

    public static void main(String[] args) {
        YieldThread yieldThread = new YieldThread();

        Thread thread = new Thread(yieldThread, "thread-A");
        Thread thread2 = new Thread(yieldThread, "thread-B");
        Thread thread3 = new Thread(yieldThread, "thread-C");

        thread.start();
        thread2.start();
        thread3.start();

    }

}
//线程的礼让  等于 获取cpu资源的线程放弃了cpu资源，重新由运行转为就绪
class YieldThread implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + " begin.....");
        //线程的礼让
        Thread.yield();
        System.out.println(Thread.currentThread().getName() + " end....");
    }
}
